package cn.jhc.service;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import cn.jhc.dao.Dao;
import cn.jhc.entity.User;

@WebServlet("/getUser.do")
public class GetUserScrvice extends HttpServlet{
    
   @Override
   protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user = null;
        String username = req.getParameter("username");
        try {
            user = new Dao().getUser(username);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Gson gson = new Gson();
        String jsonData = gson.toJson(user);
        resp.setContentType("application/json");
        resp.getWriter().print(jsonData);
    }
}
